package cn.com.cetccst.appstore.tools;

import java.io.File;
import java.text.DecimalFormat;

public class FileUtils {

    public static long getFileSize(String filePath) {
        long size = 0L;
        File file = new File(filePath);
        if (file != null && file.exists()) {
            size = file.length();
        }

        return size;
    }

    public static String getFileSize(long size) {
        if (size <= 0L) {
            return "";
        } else {
            DecimalFormat df = new DecimalFormat("##.##");
            float temp = (float) size / 1024.0F;
            return temp >= 1024.0F ? df.format((double) (temp / 1024.0F)) + "M" : df.format((double) temp) + "K";
        }
    }

}
